
import sys

sys.path.insert(0,'../')
#from django.db import models 
from mongomodel import models


import datetime

class Constants(models.ConstantsModel):

    pass

class Writer(models.EmbeddedModel):
    name = models.CharField(max_length=200)
    email = models.EmailField(max_length=200)

class Target(models.EmbeddedModel):
    name = models.CharField(max_length=200)
    url = models.URLField(max_length=200)

class Poll(models.MongoModel):
    name = models.CharField(max_length=6, db_index=True)
    question = models.CharField(max_length=200)
    release_date = models.DateTimeField()
    pub_date = models.DateField('date published')
    writer = models.DocumentField(Writer )
    targets = models.DocumentListField(Target,null=True, blank=True )
    time_list = models.ListField( models.TimeField(), blank=True, default=list )
    n_comments = models.IntegerField(null=True,default=0)
    n_pingbacks = models.IntegerField(null=True, default=0)

class Choice(models.MongoModel):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

class User(models.MongoModel):
    GENDER_CHOICES = (
        (u'M', u'Male'),
        (u'F', u'Female'),
        )
    name = models.CharField(max_length=6, db_index=True)
    gender = models.CharField(max_length=2, choices=GENDER_CHOICES)
    level = models.CharField(max_length=10, choices=(Constants.choices('user.level')))
    release_date = models.DateField()
    choices = models.DocumentListField(Choice,null=True, blank=True )
    time_list = models.ListField( models.TimeField(), blank=True, default=list )

    def was_published_today(self):
        return self.pub_date.date() == datetime.date.today()



    
